﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace BF
{
    public class ListRI<T> : CollectRecycleItem2<List<T>, T>,
                             IList<T>,
                             IList,
                             IReadOnlyList<T>
    {
        protected IList _iList;

        public T this[int index] { get => Value[index]; set => Value[index] = value; }

        object IList.this[int index] { get => Value[index]; set => Value[index] = (T)value; }

        bool IList.IsFixedSize => _iList.IsFixedSize;

        public ListRI()
        {
            Value = new List<T>();
            _iList = Value;
        }

        public void AddRange(IEnumerable<T> collection)
        {
            Value.AddRange(collection);
        }

        public int IndexOf(T item)
        {
            return Value.IndexOf(item);
        }

        public void Insert(int index, T item)
        {
            Value.Insert(index, item);
        }

        public void RemoveAt(int index)
        {
            Value.RemoveAt(index);
        }

        int IList.Add(object value)
        {
            return _iList.Add(value);
        }

        bool IList.Contains(object value)
        {
            return _iList.Contains(value);
        }

        int IList.IndexOf(object value)
        {
            return _iList.IndexOf(value);
        }

        void IList.Insert(int index, object value)
        {
            _iList.Insert(index, value);
        }

        void IList.Remove(object value)
        {
            _iList.Remove(value);
        }
    }

    /// <summary>
    /// ListRI的List
    /// </summary>
    public class ListRIList<T> : List<ListRI<T>>
    {

        public new void Clear()
        {
         
            foreach (ListRI<T> item in this)
            {
                item.ReturnToPool();
            }
            base.Clear();
        }
    }
}